*************************************************************************************************
* Documentation for Reproduction of
* Science Knowledge and Biblical Literalism. 2012. 
* Public Understanding of Science 21(3): 314-322.
* L.J Zigerell
* Stata version 9
*************************************************************************************************
*************************************************************************************************

set more off
set mem 500m
use "gss2008crosspanel.R3a.dta", clear /*This is the command to load the dataset */
* the dataset used was the 2008 GSS Cross Panel

*************************************************************************************************

* generate the weight variable
gen weight = wtnrcomb
sum weight

* generate variables to indicate whether the survey was self-administered or an interview
tab scimode
tab scimode, nol
gen scim1 = scimode 
recode scim1 (2/4=0)
gen scim2 = scimode
recode scim2 (1 3 4=0) (2=1)
gen scim3 = scimode
recode scim3 (1 2 4=0) (3=1)
gen scim4 = scimode
recode scim4 (1/3=0) (4=1)
tab1 scim1 scim2 scim3 scim4

*************************************************************************************************
*************************************************************************************************

* generate variables indicating whether a science item was answered correctly

tab h2olife, mi
gen q1 = h2olife
recode q1 (4=1) (1/3 .d .n=0) /* .d = don't know, .n = no response, .i = inapplicable */
tab q1
tab q1, mi /* this variable is 1 for correct and 0 for not correct */

gen dk1 = h2olife
recode dk1 (.d .n=1) (1/4=0)
tab dk1 /* this variable is 1 for a non-substantive response and 0 otherwise */

tab anheat, mi
gen q2 = anheat
recode q2 (2=1) (1 3/5 .d .n=0)
tab q2
tab q2, mi

gen dk2 = anheat
recode dk2 (.d .n=1) (1/5=0)
tab dk2

tab lftplane, mi
gen q3 = lftplane
recode q3 (1=1) (2/4 .d .n=0)
tab q3
tab q3, mi

gen dk3 = lftplane
recode dk3 (.d .n=1) (1/4=0)
tab dk3

tab stormtxt, mi
gen q4 = stormtxt
recode q4 (1 2=1) (3 .d .n=0)
tab q4
tab q4, mi
ttest q4, by(form) unp une

gen dk4 = stormtxt
recode dk4 (.d .n=1) (1/3=0)
tab dk4

tab litmstxt, mi
gen q5 = litmstxt
recode q5 (1 2=1) (3 .d .n=0)
tab q5
tab q5, mi
ttest q5, by(form) unp une

gen dk5 = litmstxt
recode dk5 (.d .n=1) (1/3=0)
tab dk5

tab goldfish, mi
gen q6 = goldfish
recode q6 (1=1) (2/4 .d .n=0)
tab q6
tab q6, mi

gen dk6 = goldfish
recode dk6 (.d .n=1) (1/4=0)
tab dk6

tab salth2o, mi
gen q7 = salth2o
recode q7 (3=1) (1 2 4 .d .n=0)
tab q7
tab q7, mi

gen dk7 = salth2o
recode dk7 (.d .n=1) (1/4=0)
tab dk7

tab erosion, mi
gen q8 = erosion
recode q8 (4=1) (1/3 .d .n=0)
tab q8
tab q8, mi

gen dk8 = erosion
recode dk8 (.d .n=1) (1/4=0)
tab dk8

tab genes, mi
gen q9 = genes
recode q9 (3=1) (1 2 4 .d .n=0)
tab q9
tab q9, mi

gen dk9 = genes
recode dk9 (.d .n=1) (1/4=0)
tab dk9

tab gills, mi
gen q10 = gills
recode q10 (2=1) (1 3/4 .d .n=0)
tab q10
tab q10, mi

gen dk10 = gills
recode dk10 (.d .n=1) (1/4=0)
tab dk10

tab upbreath, mi
gen q11 = upbreath
recode q11 (3=1) (1 2 4 5 .d .n=0)
tab q11
tab q11, mi

gen dk11 = upbreath
recode dk11 (.d .n=1) (1/5=0)
tab dk11

tab daynight, mi
gen q12 = daynight
recode q12 (1=1) (2/5 .d .n=0)
tab q12
tab q12, mi

gen dk12 = daynight
recode dk12 (.d .n=1) (1/5=0)
tab dk12

tab weighing, mi
gen q13 = weighing
recode q13 (3=1) (1 2 4 5 .d .n=0)
tab q13
tab q13, mi

gen dk13 = weighing
recode dk13 (.d .n=1) (1/5=0)
tab dk13

tab seesand, mi
gen q14 = seesand
recode q14 (5=1) (1/4 .d .n=0)
tab q14
tab q14, mi

gen dk14 = seesand
recode dk14 (.d .n=1) (1/5=0)
tab dk14

tab fishexp1, mi
gen q15 = fishexp1
recode q15 (1=1) (2/4 .d .n=0)
tab q15
tab q15, mi

gen dk15 = fishexp1
recode dk15 (.d .n=1) (1/4=0)
tab dk15

tab fishexp2, mi
gen q16 = fishexp2
recode q16 (2=1) (1 3/4 .d .n=0)
tab q16
tab q16, mi

gen dk16 = fishexp2
recode dk16 (.d .n=1) (1/4=0)
tab dk16

* generate a scientific literacy battery

gen q_sci = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + q14 + q15 + q16
tab q_sci
sum q_sci /* this is a battery from 0 to 16 items correct */

gen pct = q_sci/16
tab pct
sum pct /* this is a battery from 0% to 100% of items correct */


* generate an item that indicates frequency of non-substantive responses

gen dk = dk1 + dk2 + dk3 + dk4 + dk5 + dk6 + dk7 + dk8 + dk9 + dk10 + dk11 + dk12 + dk13 + dk14 + dk15 + dk16
sum dk /* this is a battery from 0 to 16 non-substantive responses */

gen pct_dk = dk/16
sum pct_dk /* this is a battery from 0% to 100% of items with non-substantive responses */

*************************************************************************************************
*************************************************************************************************

drop if pct == . /* remove all cases with no value on the pct variable */
tab1 scim1 scim2 scim3 scim4

*************************************************************************************************
*************************************************************************************************

* generate demographic controls 

tab sex, mi
gen female = sex - 1
tab female

tab race, mi
gen white = race
recode white (2 3=0)
tab white

gen black = race
recode black (1 3=0) (2=1)
tab black

tab age, mi
summ age
z1 age /* z1 is a function that recodes a variable so that a variable ranges from 0 to 1 */
// see the Dataverse files for the z1.do file //
summ z_age

tab educ, mi
gen education = educ
summ education
z1 education
tab z_education

* generate science education controls

tab hsbio, mi
gen hs_bio = hsbio
recode hs_bio (2=0)
tab hs_bio

tab hschem, mi
gen hs_chem = hschem
recode hs_chem (2=0)
tab hs_chem

tab hschem if hsbio == .i, mi

tab hsphys, mi
gen hs_phys = hsphys
recode hs_phys (2=0)
tab hs_phys

tab hsphys if hsbio == .i, mi

gen hs_sci = hs_bio + hs_chem + hs_phys
tab hs_sci
summ hs_sci
z1 hs_sci
tab z_hs_sci

tab colsci, mi
tab colscinm, mi
tab colscinm colsci, mi
gen colsci3 = colscinm
recode colsci3 (1/3=1) (4/65=2)
replace colsci3 = 0 if colsci == 2
replace colsci3 = 1 if colsci == 1 & colscinm == .d
replace colsci3 = 1 if colsci == 1 & colscinm == .n
tab colsci3 colsci, mi
sum colsci3
z1 colsci3
tab z_colsci3

* generate biblical belief variables

tab bible
tab bible, mi

gen bible_book = bible
recode bible_book (3=1) (1 2=0) (4=.)
tab bible_book

gen bible_insp = bible
recode bible_insp (2=1) (1 3=0) (4=.)
tab bible_insp

gen bible_lit = bible
recode bible_lit (1=1) (2/3=0) (4=.)
tab bible_lit

* generate religion raised control

tab fund16
tab fund16, nol
gen fundchild = fund16
recode fundchild (2/3=0)
tab fundchild

*************************************************************************************************
*************************************************************************************************

svyset [pw=weight]
svy: mean pct if bible_lit == 1 /* this is reported on page 317 of the article */
svy: mean pct if bible_insp == 1 /* this is reported on page 317 of the article */
svy: mean pct if bible_book == 1 /* this is reported on page 317 of the article */
reg pct bible_insp if bible_book == 0 [pw=weight]
reg pct bible_insp bible_book if bible_lit == 0 [pw=weight]

pwcorr bible_lit female black education hs_sci colsci3 fundchild if pct!=., sig obs /* footnote 7 */
pwcorr pct female black education hs_sci colsci3 fundchild if pct!=., sig obs /* footnote 7 */
pwcorr fundchild education hs_sci colsci3 if pct!=., sig obs /* footnote 9 */

svy: mean pct if female == 1 /* this is reported in Figure 1 of the article */
svy: mean pct if female == 0 /* this is reported in Figure 1 of the article */
reg pct female [pw=weight]

svy: mean pct if white == 0 /* this is reported in Figure 1 of the article */
svy: mean pct if white == 1 /* this is reported in Figure 1 of the article */
reg pct white [pw=weight]

svy: mean pct if hs_sci == 0 /* this is reported in Figure 1 of the article */
svy: mean pct if hs_sci > 0  /* this is reported in Figure 1 of the article */
svy: mean pct if hs_sci > 0 & hs_sci < . /* this is the correct calculation. the above line included missing values */
reg pct hs_sci [pw=weight]

svy: mean pct if z_colsci3 == 0 /* this is reported in Figure 1 of the article */
svy: mean pct if z_colsci3 > 0  /* this is reported in Figure 1 of the article */
svy: mean pct if z_colsci3 > 0 & z_colsci3 < . /* this is the correct calculation. the above line included missing values */
reg pct z_colsci3 [pw=weight]

svy: mean pct if fundchild == 1 /* this is reported in Figure 1 of the article */
svy: mean pct if fundchild == 0 /* this is reported in Figure 1 of the article */
reg pct fundchild [pw=weight]

svyset, clear

* with dks

summ dk if bible_lit  == 1 /* footnote 10 */
summ dk if bible_insp == 1 /* footnote 10 */
summ dk if bible_book == 1 /* footnote 10 */

summ pct if bible_lit  == 1
summ pct if bible_insp == 1
summ pct if bible_book == 1

di (3.61) /(16*(1-0.475))
di (2.36)/(16*(1-0.630))
di (1.95) /(16*(1-0.680))

sum hs_sci if bible_lit == 1
sum colsci3 if bible_lit == 1
sum education if bible_lit == 1

sum hs_sci if bible_insp == 1
sum colsci3 if bible_insp == 1
sum education if bible_insp == 1

sum hs_sci if bible_book == 1
sum colsci3 if bible_book == 1
sum education if bible_book == 1

reg hs_sci bible_insp bible_book [pw=weight]
reg colsci3 bible_insp bible_book [pw=weight]
reg education bible_insp bible_book [pw=weight]

* footnote

tab evolved if bible_book==1
tab evolved if bible_insp==1
tab evolved if bible_lit==1


* with no science course or education controls or religion raised

reg pct bible_lit bible_insp female white black z_age scim2 scim3 form [pw=weight] /* table 1 column 1 */
reg pct bible_lit bible_insp female white black z_age [pw=weight]

collin bible_lit bible_insp female white black z_age scim2 scim3 form

glm pct bible_lit bible_insp female white black z_age scim2 scim3 form [pw=weight], fam(bin) link(logit) scale(x2)
mfx
glm pct bible_lit bible_insp female white black z_age [pw=weight], fam(bin) link(logit) scale(x2)
mfx

* with education and science course controls

reg pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education scim2 scim3 form [pw=weight] /* table 1 column 2 */
reg pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education [pw=weight]

collin bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education scim2 scim3 form

glm pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education scim2 scim3 form [pw=weight], fam(bin) link(logit) scale(x2)
mfx
glm pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education [pw=weight], fam(bin) link(logit) scale(x2)
mfx


* with education, science course, and religion raised controls

reg pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education fundchild scim2 scim3 form [pw=weight] /* table 1 column 3 */
reg pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education fundchild [pw=weight]

collin bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education fundchild scim2 scim3 form

glm pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education fundchild scim2 scim3 form [pw=weight], fam(bin) link(logit) scale(x2)
mfx
glm pct bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education fundchild [pw=weight], fam(bin) link(logit) scale(x2)
mfx

* 

pwcorr bible_lit bible_insp female white black z_age z_hs_sci z_colsci3 z_education fundchild scim2 scim3 form, sig obs

*************************************************************************************************
